<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

    <?php
    
        session_start();
        
        if(!isset($_SESSION['user'])) {
            header("Location: ../admViews/Login.php");
        }
       
        require_once '../table_object/User.php';
        $User = new User();
        
        if(isset($_POST['name']) &&
           isset($_POST['user']) &&
           isset($_POST['pwd'])) {
            $UserVO = new UserVO;
            $UserVO->set_name(get_post('name'));
            $UserVO->set_user(get_post('user'));
            $UserVO->set_pwd(get_post('pwd'));
            $result = $User->add($UserVO);            
            
            if($result) {
                header("Location: ./UserListAll.php");
            } 
            
        }
        
        function get_post($var) {
            return mysql_real_escape_string($_POST[$var]);
        }
        
    ?>

    <head>
        <script type="text/javascript" src="../js/User.js"></script>
	<link href="../css/Main.css" rel="stylesheet" type="text/css">
        <title>Web App Dev - Mcgill - <?php echo $_SESSION['user']; ?></title>
    </head>
    
    <body>
        <h3>User Master - Create</h3>
        <form name="userForm" action="./UserCreate.php" method="post" onsubmit="return validateForm()">
            <table class="tableinputdata">
                <tr>
                    <td align="right">
                        Name
                    </td>
                    <td>
                        <input type="text" name="name" autofocus/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        User
                    </td>
                    <td>
                        <input type="text" name="user"/>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        Password
                    </td>
                    <td>
                        <input type="password" name="pwd"/>
                    </td>
                </tr>
            </table>
            <table>
                <tr>
                    <td>
                        <input type="submit" value="Save">
                    </td>
                    <td>
                        <input type="button" value="List All" onclick="goTo('./UserListAll.php')"/>
                    </td>
                </tr>
            </table>
            <p id="dbFailedMessage"><?php echo mysql_error(); ?>.</p>
      </form>
   </body>
</html>









